// 拼接HTTPUrl
function jointHttpUrl(type, pathname) {
  return window.RPConfig[type] + pathname;
}
function url(type, pathname) {
  return window.RPConfig[type] + pathname;
}

const userManageAPI = {
  // ladp用户
  getLdapUser: params => {
    return $http.post(url("ldap", "/ldap/user/findUser"), params);
  },
  // 新增ladp用户
  addLdapUser: params => {
    return $http.post(url("mgt", "/user/batch/add"), params);
  },
  // 新增Ldap用户后，再次调用
  alreadyAddUser: params => {
    return $http.post(url("ldap", "/ldap/user/save/alreadyAddUser"), params);
  },
  // 删除Ldap用户后，再次调用
  alreadydelUser: params => {
    return $http.post(url("ldap", "/ldap/user/dele/alreadyAddUser"), params);
  },
  // 新增用户
  addUser: params => {
    return $http.post(jointHttpUrl("mgt", "/user/add"), params);
  },
  // 解锁
  unlock: params => {
    return $http.post(jointHttpUrl("userCenter", "/user/updateHomeUserInfo"), params);
  },
  //批量删除用户
  deleteUsers: params => {
    return $http.post(jointHttpUrl("userCenter", "/user/deleteByIds"), params);
  },
  // 编辑用户信息
  updateUser: params => {
    return $http.post(jointHttpUrl("mgt", "/user/updateUser"), params);
  },
  // 根据ID获取角色分配数据
  // getRoleByUserId: id => {
  //   return $http.post(jointHttpUrl("mgt", "/role/getRoleByUserId?userId=" + id), {});
  // },
  // 根据用户ID查找组织
  findOrgListByUserId: id => {
    return $http.post(jointHttpUrl("mgt", "/role/findOrgListByUserId?userId=" + id), {});
  },
  // 获取用户管理列表数据
  getUserListPage: param => {
    return $http.post(jointHttpUrl("mgt", "/user/getUserListPages"), param).then(response => response.data);
  },
  // 获取用户管理列表数据
  getUserListPageNoTotal: param => {
    return $http.post(jointHttpUrl("mgt", "/user/getUserListPageNoTotal"), param).then(response => response.data);
  },
  // 变更数据状态: 启用 | 冻结
  updateStatus: row => {
    let pathname = "/user/updateStatus?id=" + row.id + "&locked=" + (row.locked == "1" ? "0" : "1");
    return $http.post(jointHttpUrl("userCenter", pathname));
  },
  // 获取自建应用数据
  getSelfBuiltApp: param => {
    return $http
      .post(
        jointHttpUrl(
          "mgt",
          "/application/getCurrentUserPlatformApplications?category=" +
            param.category +
            "&tenantCode=" +
            param.tenantCode +
            "&nameOrCode=" +
            param.nameOrCode
        )
      )
      .then(response => response.data);
  },
  // 通过ID分配的第三方应用
  getUserInfoById: params => {
    return $http.get(jointHttpUrl("userCenter", "/user/getByUserId"), params).then(response => response.data);
  },
  // 获取用户分配的应用
  getAppListByUserId: ({ userId, tenantCode }) => {
    return $http
      .get(jointHttpUrl("userCenter", `/user/listApplications?userId=${userId}&tenantCode=${tenantCode}`))
      .then(response => response.data);
  },
  // 根据当前用户id  获取组织树数据
  getOrgTree: params => {
    return $http
      .post(
        jointHttpUrl("mgt", `/organization/getOrgTreeByUser?orgType=${2}&enabled=${1}&nameOrCode=${params.nameOrCode}`),
        params
      )
      .then(response => response.data);
  },
  // 获取关联员工列表
  getEmployee: param => {
    return $http.post(jointHttpUrl("mgt", "/employee/employeeOrg/list/page"), param).then(res => res.data);
  },
  // 获取第三方应用
  getThirdPartyApp: param => {
    return $http
      .get(`${window.RPConfig.setting}/valueset/vsItem/list?vsCode=${param.code}&nameOrCode=${param.nameOrCode}`, {})
      .then(response => response.data);
  }
};

export default userManageAPI;
